package com.easygo.controller;

import com.easygo.client.AdminClient;
import com.easygo.common.ResultEnum;
import com.easygo.common.ResultResponse;
import com.easygo.pojo.Admin;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 徐策
 * @date 2020/1/7 15:39
 */
@Controller
@Scope("prototype")
public class AdminWebController {
    @Resource
    AdminClient adminClient;

    /**
     * 登录方法 返回ResultResponse
     */
    @PostMapping("/admin_login")
    @ResponseBody
    public ResultResponse adminLogin(Admin admin){
        Admin loginAdmin = adminClient.AdminLogin(admin);
        if(loginAdmin!=null){
            if(loginAdmin.getStatus().equals("0")){
                return  ResultResponse.fail(ResultEnum.CTLOGIN);
            }else {
                return ResultResponse.success(ResultEnum.SUCCESS);
            }
        }else {
            return ResultResponse.fail(ResultEnum.FAIL);
        }

    }
}
